/* -----------------------------------------------------------------------
 * Unit Test 4 = Testing shuffle
 * Using provided template for testUpdateCoins.c
 *
 * -----------------------------------------------------------------------
 */

#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"
#include <stdlib.h>
#include <time.h>

// set NOISY_TEST to 0 to remove printfs from output
#define NOISY_TEST 1

void testShuffle() {
    int i, j;
    
    struct gameState *G = malloc(sizeof(struct gameState));
    struct gameState *Gcpy = malloc(sizeof(struct gameState));
    int testCases = 500;
    //Deck starts with 3 cards
    for (i = 0; i < 3; i++)
        G->deck[0][i] = rand() % 27; 
    G->deckCount[0] = 3;

    printf ("TESTING shuffle():\n");
    for (i = 3; i <= testCases; i++) 
    {
        G->deck[0][i] = rand() % 27; //random card for the deck
        G->deckCount[0]++;

#if (NOISY_TEST == 1)
        printf("Test player %d with %d deck card(s).\n", 0, G->deckCount[0]);
#endif
        memcpy(Gcpy, G, sizeof(struct gameState));
        shuffle(0, G);

        int stateShuffled = 0;
        for (j = 0; j < G->deckCount[0]; j++) {
            if (G->deck[0][j] != Gcpy->deck[0][j]) { // If any one card is different
                stateShuffled = 1;
                break;
            }
        }

        assert(stateShuffled == 1); 
    }

    printf("All tests passed!\n");
    free(G);
    free(Gcpy);
}



int main() {
    srand(time(NULL));
    testShuffle();
    return 0;
}
